package com.kfm.jdbc.day0328;

import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Demo02 {

    public static void main(String[] args) {
        try {
            // 内省机制
            PropertyDescriptor property = new PropertyDescriptor("name", Student.class);
//            System.out.println(property);

            Method readMethod = property.getReadMethod();
            Method writeMethod = property.getWriteMethod();

            Class<Student> studentClass = Student.class;
            Student student = studentClass.newInstance();

            Object invoke1 = writeMethod.invoke(student, "xi'an");
            System.out.println(invoke1);

            Object invoke = readMethod.invoke(student);
            System.out.println(invoke);
        } catch (IntrospectionException e) {
            throw new RuntimeException(e);
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        }


    }
}
